package com.service.impl;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bean.LineArticle;
import com.dao.LineArticleDao;
import com.service.LineArticleService;
import com.util.CacheUtil;
import com.util.LoggerUtil;
import com.util.Pager;
import com.util.Redis;
@Component
public class LineArticleServiceImpl implements LineArticleService{

	public static Logger logger=Logger.getLogger(LineArticleServiceImpl.class);
	@Autowired
	private LineArticleDao lineArticleDao;

	@Override
	public Map<String, Object> selectLineArticle(Integer curPage,
			Integer pageSize, JSONObject logs) {
		Map<String, Object> map=new HashMap<>();
		String keys =logs.getString("keys");
		try {
			Pager<LineArticle> articles=lineArticleDao.selectLineArticle(curPage, pageSize);
			if(articles!=null&&articles.getData().size()>0){
				map.put("result", "success");
				map.put("rows", articles);
				if(StringUtils.isNotEmpty(keys)){
					Redis.setRedisData(keys, CacheUtil.getValue(map));
				}
				LoggerUtil.backlogsSuccess(logs, logger);
			}else{
				map.put("result", "false");
				LoggerUtil.backlogsFalseNOData(logs, logger);
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
		}
		return map;
	}
}
